var DEBUG=true;
var Log=function(textLog){
  if(DEBUG)console.log(textLog);
}
Html=function(){
  var self=this;

  self.row=function(num){
    return ' <tr> <td class="id-task">'+num+'</td> <td class="actions-task"><input type="text" class="span8" /></td> <td class="del-task"> <button onclick="behaviour.delRow($(this).parent().parent());" class="btn btn-danger" > <i class="icon-remove"></i> Del</button> </td> ';
  }
}
html=new Html();

Behaviour=function(){
  var self=this;

  self.numRows=0;

  self.updateRows=function(){
    $('#numTasks').html(self.numRows);
    return self;
  }

  self.mainMenu=function(link){
    $('.active').each(function(){
      $(this).removeClass('active');
      if($(this).attr('id')!=undefined)
        $(this).css({'display':'none'});
    });
    $(link).parent().addClass('active');
    $('#'+$(link).attr('link')).addClass('active');
    $('#'+$(link).attr('link')).css({'display':'block'});
  }

  self.addRow=function(table){
    table.append(html.row(++self.numRows));
    self.updateRows();
    return self;
  }

  self.delRow=function(row){
    var table=row.parent();
    row.remove();
    self.numRows--;
    var rows=table.children();
    for(var i=1;i<rows.length;i++){
      $($(rows[i]).children()[0]).html(i);
    }
    self.updateRows();
    return self;
  }
}

behaviour=new Behaviour();
